<template>
    <div>
        <!--        添加分类-->
        <div style="padding: 2% 2% 2% 2%;margin: 1% 0 1% 1%;width: 30%;min-width: 250px" class="shadow">
            <h3>添加分类</h3>
            <p>ps: ...代表无父类</p>
            <el-form style="margin-top: 3%;" :model="editedResults" ref="form" label-width="80px">
                <el-form-item label="父级分类" style="">
                    <el-select v-model="editedResults.ccid" placeholder="请选择活动区域">
                        <el-option label="..." value="0"/>
                        <el-option :label="item.name" :value="item.cid"
                                   v-for="item in fatherClassificationList"/>
                    </el-select>
                </el-form-item>
                <el-form-item label="分类名称">
                    <el-input v-model="editedResults.name"/>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="btn_save()" style="width: 100%">添加</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<script>
    let that
    export default {
        name: "Add",
        data() {
            return {
                fatherClassificationList: [],
                editedResults: {
                    cid: 0,
                    ccid: 0,
                    name: ''
                },
            }
        },
        mounted() {
            that = this;
            //    获取所有的父分类
            that.$Axios(that.$store).get(that.CLASSIFICATION_API + "/father")
                .then(function (result) {
                    that.fatherClassificationList = result.data.data;
                });
        },
        methods: {
            btn_save() {
                that.$Axios(that.$store).post(that.CLASSIFICATION_API + '/save_and_update', that.editedResults)
                    .then(function (result) {
                        that.$router.go(0);
                    });
            },
        }
    }
</script>

<style scoped src="../../../static/md/markdown.css">

</style>